package JUNHO.serializacao;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;


class Carro implements Serializable
{
	private String marca = "GM";
	private String modelo = "LUXO";
	
	public void setMarca(String m)
	{
		this.marca = m;
		
	}
	
	public String getMarca()
	{
		return this.marca;
	}
	
	public String toString()
	{
		return marca+modelo;
	}
}

public class Seri {
	
	public static void main(String[] args) {
		Carro c1 = new Carro();
		System.out.println(c1);
		
		try 
		{
			FileOutputStream f = new FileOutputStream("teste1.txt");
			ObjectOutputStream o = new ObjectOutputStream(f);
			
			o.writeObject(c1);
			o.close();
			
			c1.setMarca("Volks");
			
			FileInputStream fi = new FileInputStream("teste1.txt");
			ObjectInputStream oi = new ObjectInputStream(fi);
			Carro x = (Carro) oi.readObject();
			oi.close();
			
			System.out.println(x);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}

}
